package acwing._1_1AlgorithmBasic._4Math;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._1_1AlgorithmBasic._4Math
 * @File : Q0885.java
 * @Author : WangRuoyu
 * @Date : 2023/4/5 11:05
 */

import java.io.*;

public class Q0885 {

    static int[][] cNums() {
        final int MOD = 1000000007;
        int[][] res = new int[2001][2001];
        for (int i = 0; i <= 2000; ++i) {
            for (int j = 0; j <= 2000; ++j) {
                if (i < j) continue;
                if (j == 0 || j == i) {
                    res[i][j] = 1;
                } else {
                    res[i][j] = (res[i - 1][j - 1] + res[i - 1][j]) % MOD;
                }
            }
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] words = br.readLine().split(" ");
        int n = Integer.parseInt(words[0]);
        int[][] cnums = cNums();
        for (int i = 0; i < n; ++i) {
            words = br.readLine().split(" ");
            int a = Integer.parseInt(words[0]);
            int b = Integer.parseInt(words[1]);
            wr.write(cnums[a][b] + "\n");
        }
        wr.flush();
    }
}
